package com.bjpowernode.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MybatisUtil {
    public static SqlSession getSqlSession()  {
        String mybatis="mybatis.xml";
        InputStream in= null;
        try {
            in = Resources.getResourceAsStream(mybatis);
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactoryBuilder sqlSessionFactroyBuilder=new SqlSessionFactoryBuilder();
        SqlSessionFactory sqlSessionFactory=sqlSessionFactroyBuilder.build(in);
        SqlSession sqlSession=sqlSessionFactory.openSession();
        return sqlSession;
    }
}
